-
Notifications
You must be signed in to change notification settings - Fork 0
Optimize transitiveDirtyListBottomUpDiff using Pearce-Kelly algorithm for incremental topological ordering #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: improve-hls-runtime-keep-async-only-databse-keys-upsweep-tmp
Are you sure you want to change the base?
Conversation
Co-authored-by: soulomoon <[email protected]>
Co-authored-by: soulomoon <[email protected]>
|
||
-- | Get all keys sorted by their topological order | ||
getOrderedList :: TopoOrder -> STM [Key] | ||
getOrderedList TopoOrder{..} = do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOrderedList is O(n log n), not good, it's better to keep an updated ordered list instead of computing it right at time. @copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed getOrderedList
as it was not used anywhere and had O(n log n) complexity. The function is now eliminated from the API. (commit 6fb2e55)
-- | Topological ordering structure for Pearce-Kelly algorithm | ||
-- Maps each Key to its topological order number (smaller = earlier in order) | ||
data TopoOrder = TopoOrder | ||
{ topoOrderMap :: !(TVar (Map.HashMap Key Int)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use StmContainers.Map
here? @copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed TopoOrder
to use StmContainers.Map
instead of TVar (Map.HashMap ...)
. This is consistent with the rest of the codebase and provides better STM performance. (commit 6fb2e55)
…rderedList Co-authored-by: soulomoon <[email protected]>
Plan: Implement Pearce-Kelly algorithm for incremental topological ordering ✅ COMPLETE
The goal is to optimize
transitiveDirtyListBottomUpDiff
by using the Pearce-Kelly algorithm to maintain a running topological order of the dependency graph.Implementation Plan
StmContainers.Map
instead ofTVar (Map.HashMap ...)
for better STM performancegetOrderedList
function with O(n log n) complexityRecent Changes (Review Feedback)
Changed
TopoOrder
to useStmContainers.Map
:TVar (Map.HashMap Key Int)
withSMap.Map Key Int
readTVar
/writeTVar
operationsRemoved
getOrderedList
function:Implementation Details
New Module: TopoSort.hs
Created a new module
Development.IDE.Graph.Internal.TopoSort
implementing the Pearce-Kelly algorithm:StmContainers.Map
addEdge
to incrementally update order when new dependencies are addedgetAffectedKeysInOrder
to efficiently sort keys by topological orderUpdated Types.hs
Added
TopoOrder
data structure toSchedulerState
:SMap.Map Key Int
Updated Database.hs
newDatabase
updateReverseDeps
to calladdEdge
when dependencies changetransitiveDirtyListBottomUpDiff
to usegetAffectedKeysInOrder
for efficient sortingPerformance Benefits
The Pearce-Kelly algorithm ensures that the topological order is maintained with minimal overhead during dependency updates, making
transitiveDirtyListBottomUpDiff
faster especially for large dependency graphs.Testing
Files Changed
hls-graph/hls-graph.cabal
- Added new module to exposed moduleshls-graph/src/Development/IDE/Graph/Internal/Types.hs
- Added TopoOrder data structure using StmContainers.Maphls-graph/src/Development/IDE/Graph/Internal/TopoSort.hs
- New module with Pearce-Kelly implementation, removed unused getOrderedListhls-graph/src/Development/IDE/Graph/Internal/Database.hs
- Integration of topological orderinghls-graph/README.md
- Documentation of the optimizationhls-graph/test/DatabaseSpec.hs
- Fixed test warningsOriginal prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.